<template>
  <div class="box">
    <div class="title">
      <van-icon class="icon" name="arrow-left" @click="returnFn" />
      收货地址
    </div>
    <div class="content">
      <div
        class="list"
        @click="modifyFn(item)"
        v-for="item in info.data"
        :key="item.id"
      >
        <div class="info">
          <div class="name">
            {{ item.name }}
            <span style="letter-spacing: 0px">{{ item.phone }}</span>
          </div>
          <div class="address">{{ item.fullAddress }}</div>
        </div>
        <div class="iconButton">
          <div class="moren" v-if="item.defaultStatus == 1">默认</div>
          <van-icon @click="modifyFn(item)" class="icon" name="edit" />
        </div>
      </div>
    </div>
    <div class="button" @click="modifyFn(false)">新增收货地址</div>
  </div>
</template>

<script>
import { defineComponent, getCurrentInstance, onMounted, reactive } from "vue";
import { useRouter } from "vue-router";
import { getAddressList } from "@/api/http.js";

export default defineComponent({
  setup() {
    const { proxy } = getCurrentInstance();
    const router = useRouter();
    const returnFn = () => {
      router.go(-1);
    };

    const modifyFn = (item) => {
      // provide("item", item);
      router.push({
        name: "AddressSon",
        params: item,
      });
    };

    const info = reactive({
      data: {},
    });
    const getInfo = async () => {
      const { data } = await getAddressList();
      info.data = data;
      console.log("获取收货地址---", data);
    };

    onMounted(() => {
      getInfo();
    });

    return {
      returnFn,
      proxy,
      modifyFn,
      info,
    };
  },
});
</script>

<style lang="less" scoped>
.box {
  min-height: 100vh;
  background-color: var(--backColorTwo);
  color: #666666;
  .title {
    width: 100%;
    height: 60px;
    font-size: 1.125rem;
    font-family: PingFang SC;
    font-weight: bold;
    color: #fff;
    text-align: center;
    line-height: 60px;
    position: relative;
    padding: 0 4%;
    background-color: #212121;

    .icon {
      position: absolute;
      top: 50%;
      left: 10px;
      font-size: 1.5rem;
      transform: translateY(-50%);
    }
  }
  .content {
    padding: 20px 4%;
    color: var(--textColor);

    .list {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: var(--backColor);
      padding: 15px 20px;
      border-radius: 10px;
      margin-bottom: 10px;

      .info {
        .name {
          font-size: 1.1rem;
          font-family: PingFang SC;
          font-weight: bold;
          letter-spacing: 2px;

          span {
            color: var(--textColorTwo);
            font-weight: 400;
          }
        }
        .address {
          margin-top: 15px;
          font-size: 0.9rem;
          font-weight: 400;
          opacity: 0.8;
          width: 200px;
          letter-spacing: 0.5px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }

      .iconButton {
        display: flex;
        justify-content: center;
        align-items: center;

        .moren {
          background: #db2828;
          border-radius: 20px;
          font-size: 0.7rem;
          letter-spacing: 2px;
          text-align: center;
          line-height: 25px;
          width: 50px;
          height: 25px;
          color: #fff;
        }
        .icon {
          font-size: 1.4rem;
          margin-left: 20px;
        }
      }
    }
  }
  .button {
    height: 45px;
    background: #f04949;
    border-radius: 50px;
    font-size: 1.1rem;
    font-family: PingFang SC;
    font-weight: 400;
    color: #fff;
    text-align: center;
    line-height: 45px;
    margin-top: 20px;
    margin-left: 8%;
    margin-right: 8%;
  }
}
</style>
